/// <reference path="../_all.ts" />

module Application.Utility {

    export class Navigation {
        public icon: string;
        constructor(public title: string, public url: string, public active: boolean, public submenu: boolean) {
            this.setIcon('home');
        }
        // We use a method to easily move to another bootstrap/glyphicon which doesn't use 'icon-' but 'glyphicon-'
        public setIcon(name: string) {
            this.icon = 'icon-' + name;
        }
    }

    export class Navigations {
        public items: Navigation[];
        public rightitems: Navigation[];

        constructor() {
            this.items = [];
            this.rightitems = [];
        }

        public AddLink(title: string, url: string, active: boolean, submenu: boolean, icon?:string) {
            // Making sure the URLs are Angular nav compatible, the check for the "/" is to avoid breaking external urls
            if (url.indexOf('#') != 0 && url.indexOf('/') == 0) {
                url = '#' + url;
            };
            var link = new Navigation(title, url, active, submenu);
            if (icon) { link.setIcon(icon); };
            if (this.items == null) this.items = [];
            this.items.push(link);
        }

        public AddLinkRight(title: string, url: string, active: boolean) {
            // Making sure the URLs are Angular nav compatible, the check for the "/" is to avoid breaking external urls
            if (url.indexOf('#') != 0 && url.indexOf('/') == 0) {
                url = '#' + url;
            };
            var link = new Navigation(title, url, active, false);
            if (this.rightitems == null) this.rightitems = [];
            this.rightitems.push(link);
        }

        public Clear() {
            if (this.items != null && this.items.length > 0) {
                this.items.length = 0;
            };
            if (this.rightitems != null && this.rightitems.length > 0) {
                this.rightitems.length = 0;
            };
        }
    }

}